<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.*" %>
<%--
  Created by IntelliJ IDEA.
  User: 电脑
  Date: 2024/10/27
  Time: 23:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    String username = "root";
    String pwd = "990106";
    String url="jdbc:mysql://localhost:3306/text?serverTimezone=Asia/Shanghai";
    Class.forName("com.mysql.cj.jdbc.Driver");
    Connection conn = DriverManager.getConnection(url,username,pwd);
    String sql ="delete from student where number=?";
    java.sql.PreparedStatement preparedStatement = conn.prepareStatement(sql);

    preparedStatement.setString(1,"2");

    int result=preparedStatement.executeUpdate();
    if(result>0)
        out.print("<script type='text/javascript'>alert('删除成功');</script>");
    else
        out.print("<script type='text/javascript'>alert('删除失败');</script>");
    sql = "select * from student";
    ResultSet rs = preparedStatement.executeQuery(sql);
%>
<table border="1">
    <tr colsspan="4" style="font-size: x-large;alignment: center">学生信息表</tr>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>出生日期</td>
        <td>班级</td>
    </tr>
    <%while (rs.next()){%>
    <tr style="text-align: center">
        <td><%=rs.getString(1)%></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString("birthday")%></td>
        <td><%=rs.getString("stuclass")%></td>
    </tr>
    <%}%>
    <%rs.close();
        preparedStatement.close();
        conn.close();
    %>
</table>
</table>

</body>
</html>
